﻿


<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>语音播报</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="../../layuiAdmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="../../layuiAdmin/style/admin.css" media="all">
</head>
<body>

    <div class="layui-fluid">
        <div class="layui-row layui-col-space15">
            <div class="layui-col-md12">
                <div class="layui-card">
                    <div class="layui-card-header">语音播报</div>
                    <div class="layui-card-body" pad15>

                        <div class="layui-form" wid100 lay-filter="">
                            <div class="layui-form-item">
                                <label class="layui-form-label">语音类型</label>
                                <div class="layui-input-block">
                                    <select name="voice" lay-verify="required" lay-search>
                                    </select>
                                </div>
                            </div>
                            <div class="layui-form-item layui-form-text">
                                <label class="layui-form-label">播报内容</label>
                                <div class="layui-input-block">
                                    <textarea name="msg" class="layui-textarea" lay-verify="required"></textarea>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <div class="layui-input-block">
                                    <button class="layui-btn" lay-submit lay-filter="form-submit">播放</button>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label"></label>
                                <audio controls id="myAudio">
                                    <source src="" id="audioSource" type="audio/mpeg">
                                    您的浏览器不支持 audio 元素。
                                </audio>
                            </div>
                        </div>

                    </div>
                </div>
            </div>
        </div>
    </div>

    <script src="../../layuiAdmin/layui/layui.js"></script>
    <script>
        layui.config({
            base: '../../layuiAdmin/', //静态资源所在路径
            version: top.layui.setter.version
        }).extend({
            index: 'lib/index' //主入口模块
        }).use(['index', 'form'], function () {
            var $ = layui.$,
                form = layui.form,
                admin = layui.admin
            $("select[name='voice']").SetSelect({
                url: '/api/TTS/GetVoices',
                async: true,
                id: 'cId',
                text: 'cName',
                description: '请选择语音',
                success: function () {
                    form.render('select');
                }
            });
            form.on('submit(form-submit)', function (data) {
                var field = data.field; //获取提交的字段
                //提交
                admin.req({
                    type: 'post',
                    url: "/api/TTS/ConvertAudio",
                    data: field,
                    success: function (r) {
                        if (r.code == 200) {
                            var audioSource = document.getElementById('audioSource');
                            audioSource.src = top.layui.setter.baseUrl + r.data;
                            var myAudio = document.getElementById('myAudio');
                            myAudio.load(); // 重新加载音频
                            myAudio.play(); // 播放音频
                        } else {
                            layer.msg('播放失败!\n' + data.msg, { icon: 2, time: 1000 });
                        }
                    }
                });
            });

        });
    </script>
</body>
</html>
